//
// ${App.Name}
//
// Copyright (C) 2005 Matthew Ward
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
//
// Matthew Ward (mrward@users.sourceforge.net)


using NUnit.Framework;
using SoapTrace.Core.Formatters;
using System;

namespace SoapTrace.Tests.TextFormatting
{
	/// <summary>
	/// Base class for tests that test the 
	/// <see cref="SoapTrace.Core.Formatters.FormattedText.SetColour"/>
	/// method.
	/// </summary>
	[ TestFixture ]
	public abstract class TextFormattingTestFixtureBase
	{
		private FormattedText m_FormattedText;
		private FormattedTextItemCollection m_ExpectedItems;
		
		/// <summary>
		/// Gets the FormattedText object for this test fixture.
		/// </summary>
		public FormattedText FormattedText
		{
			get
			{
				return m_FormattedText;
			}
			
			set
			{
				m_FormattedText = value;
			}
		}
		
		/// <summary>
		/// Gets the items that are expected in the 
		/// formatted text object.
		/// </summary>
		public FormattedTextItemCollection ExpectedItems 
		{
			get
			{
				return m_ExpectedItems;
			}
			
			set
			{
				m_ExpectedItems = value;
			}
		}

		/// <summary>
		/// Tests that the colours are correct.
		/// </summary>
		[ Test ]
		public void ExpectedColours( )
		{
			for( int i = 0; i < m_ExpectedItems.Count; ++i )
			{
				FormattedTextItem ExpectedItem = m_ExpectedItems[ i ];
				FormattedTextItem ActualItem = m_FormattedText.Items[ i ];
				
				Assert.AreEqual( ExpectedItem.Colour, ActualItem.Colour,
				                String.Concat( "Colour incorrect for Item=", ExpectedItem.Text ) );
			}
		}
		
		/// <summary>
		/// Tests that the text is correct.
		/// </summary>
		[ Test ]
		public void ExpectedText( )
		{
			for( int i = 0; i < m_ExpectedItems.Count; ++i )
			{
				FormattedTextItem ExpectedItem = m_ExpectedItems[ i ];
				FormattedTextItem ActualItem = m_FormattedText.Items[ i ];
				
				Assert.AreEqual( ExpectedItem.Text, ActualItem.Text,
				                String.Concat( "Text incorrect for Item=", ExpectedItem.Text ) );
			}
		}	
		
		/// <summary>
		/// Checks that the number of coloured items is correct.
		/// </summary>
		[ Test ]
		public void ExpectedItemCount( )
		{
			Assert.AreEqual( m_ExpectedItems.Count, m_FormattedText.Items.Count,
			                "Unexpected item count." );
		}		
	}
}
